<?php
namespace App\Models\Msg;

use Illuminate\Database\Eloquent\Model;

/***
 * Icon 被评论的类
 * @author lee
 *
 */
class msgCommentM extends Model
{
    public static  $STable="lee_msg_becomment";
    protected  $table="lee_msg_becomment";
    
    
    /***
     * 添加数据记录 ['userid'=>1,'iconid'=>2,'commentid'=>3,'becmtuserid'=>1]
     * @param array $Item
     */
    static public function addItem(array $Item){
        $inst=new msgCommentM();
        foreach ($Item as $k=>$v){
            $inst->$k=$v;
        }
        $inst->save();
    }
    
    
    /**
     * 删除 comment 消息
     * @param array $item ['commentid'=>3]
     */
    static public function dltItem(array $item){
        $item['ispushed']=false;
        self::where($item)->delete();
    }
    
    
    /**
     * 返回未读信息
     * @param unknown $userid
     * @param number $lmt
     * @param number $offset
     */
    static public function getUnreadMsg($userid,$lmt=10,$offset=0){
        return  self::where(['becmtuserid'=>$userid,'ispushed'=>false])->select('id','cmtid','userid')
            ->offset($offset)->limit($lmt)->get();
    }
    
    /**
     * 返回 已读信息
     * @param unknown $userid
     * @param number $lmt
     * @param number $offset
     */
    static  public function getReadMsg($userid,$lmt=10,$offset=0){
        return  self::where(['becmtuserid'=>$userid,'ispushed'=>true])->select('id','cmtid','userid')
            ->offset($offset)->limit($lmt)->get();
    }
    
    /***
     * 返回  用户的  未推送消息个数
     * @param int $userid
     */
    static public function msgCount($userid){
        return self::where(['becmtuserid'=>$userid,'ispushed'=>false])->count();
    }
    
    
    /***
     *  标识信息已推送
     * @param  $msgid
     */
    static public function markReaded($msgid){
        self::where('id',$msgid)->update('ispushed',true);
    }
    
    
}

?>